package com.example.f8399.testdemo.activity;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;

import com.blankj.utilcode.util.ToastUtils;
import com.example.f8399.testdemo.BaseActivity;
import com.example.f8399.testdemo.R;
import com.example.f8399.testdemo.databinding.ActivityFabBinding;

/**
 * @description 显示float action button的界面.
 *
 * @author lcfeng
 * @date   2018/8/28 17:04.
**/
public class FABActivity extends BaseActivity {

    ActivityFabBinding mBinding;
    Animation fabopen,fabclose,fabRclockwise,fabRaniclockwise;
    boolean isOpen ;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mBinding = DataBindingUtil.setContentView(this,R.layout.activity_fab);
        mBinding.setAc(this);

        initView();
    }

    private void initView() {

        //注意你的build.gradle文件中有没有com.android.support:desig:27.1.1特性，这个可能会有影响
        fabopen = AnimationUtils.loadAnimation(this, R.anim.fab_open);
        fabclose = AnimationUtils.loadAnimation(this, R.anim.fab_close);
        fabRclockwise = AnimationUtils.loadAnimation(this, R.anim.rotate_clockwise);
        fabRaniclockwise = AnimationUtils.loadAnimation(this, R.anim.rotate_anticlockwise);
    }

    public void showFAB(View view) {
        if (isOpen) {
            isOpen = false;
            mBinding.fabUp.startAnimation(fabclose);
            mBinding.fabDown.startAnimation(fabclose);
            mBinding.fab.startAnimation(fabRaniclockwise);
            mBinding.fabUp.setClickable(false);
            mBinding.fabDown.setClickable(false);

        } else {
            isOpen = true;
            mBinding.fabUp.startAnimation(fabopen);
            mBinding.fabDown.startAnimation(fabopen);
            mBinding.fab.startAnimation(fabRclockwise);
            mBinding.fabUp.setClickable(true);
            mBinding.fabDown.setClickable(true);
        }
    }
}
